import HttpUtil from './HttpUtil';
import EncryptUtil from './EncryptUtil';
/**
 * 车智赢+网络请求规则
 */
export default class AHHttpUtil {
    static APP_KEY = 'com.che168.www';

    /**
     * 拼装公共请求参数，以及参数sign加密
     */
    static handleParams = (params) => {
        if (params == undefined) {
            params = {}
        }
        params = { ...params, _appid: 'atc.android', channelid: 'csy', appversion: '1.9.12', udid: 'abc|4774748|dfdjknjsdfdsfdsfdsdf' }
        var signStr = AHHttpUtil.APP_KEY;
        for (const key of Object.keys(params)) {
            signStr = signStr + key + params[key];
        }
        signStr += AHHttpUtil.APP_KEY;
        return { ...params, _sign: EncryptUtil.md5(signStr) }

    }
    /**
     * 定制网络请求
     * 
     * @param {请求方式} method 请求方式
     * @param {请求url} url 
     * @param {请求参数} params 
     */
    static request(method, url, params) {
        return HttpUtil.doRequest(method, url, AHHttpUtil.handleParams(params));

    }
}